/**
 * @author Luc Yriarte
 * 
 * Licence : BSD http://www.opensource.org/licenses/bsd-license.php
 *  
 */
package physicSim;

import basicSim.Vector;

public class Spring extends ForceGenerator {
	/** spring length at rest */
	public double length=1;
	public double stiffness=1;
	public Vector stretch;
	
	/**
	 * 
	 */
	public Spring() {
		super();
	}

	/**
	 * @param length
	 * @param stiffness
	 * vertical stretch vector of length descending the y axis
	 */
	public Spring(double length, double stiffness) {
		super();
		this.length = length;
		this.stiffness = stiffness;
		this.stretch = new PhysicVector(0,-length,0);
	}
	
	public Vector getForceVector() {
		return Vector.MatrixAsVector(stretch.unitVector().mulNumThis(-stiffness*(stretch.norm()-length)));
	}
}
